package cn.initcap.designpattern.pattern.behavioral.interpreter;

/**
 * @author initcap
 * @date Created in 2018/10/14 PM7:08.
 */
public class OperatorUtil {
    private static final String ADD = "+";
    private static final String MULTI = "*";

    public static boolean isOperator(String symbol) {
        return (symbol.equals(ADD) || symbol.equals(MULTI));
    }

    public static Interpreter getExpressionObject(Interpreter firstExpression, Interpreter secondExpression, String symbol) {
        if (symbol.equals(ADD)) {
            return new AddInterpreter(firstExpression, secondExpression);
        } else if (symbol.equals(MULTI)) {
            return new MultiInterpreter(firstExpression, secondExpression);
        }
        return null;
    }
}
